<?php
namespace Home\Controller;
use OT\DataDictionary;
class LeiController extends HomeController {
    public function index(){
        $id=I('get.id');
        $name=I('title');
        if ($name!='') {
          $where['title']=array('like',"%{$name}%");
          $shops=M('shop')->where($where)->select(); 
        }elseif($id!='') {
        $list=$this->digui($id);
                foreach ($list as $v) {
                    $shop=M('shop')->where(array('cate'=>$v['id']))->select();
                    if ($shop) {
                        foreach ($shop as $a) {
                        $p=array();
                        $price=M('price')->where(array('pid'=>$a['id']))->order('sprice',desc)->limit(1)->select();
                        $lists[price]=$price[0]['sprice'];
                        $lists[gid]=$price[0]['id'];
                        $lists[id]=$a['id'];
                        $lists[title]=$a['title'];  
                        $lists[pic]=$a['pic'];
                        $shops[]=$lists;
                        }
                    }
                }    
        }
    	// array_multisort($shops,"[0]['id']");
    	// dump($shops);
    	
    	
		$this->assign('shops',$shops);
    	$this->display();
    }
    public function digui($id=0,$return=array()){
		$res=M('category')->where(array('pid'=>$id))->select();		
		if($res){
			foreach ($res as $v) {
				$return[]=$v;
				$return=$this->digui($v['id'],$return);
			}	
		}
		return $return;
	}
}
